//
//  LTFReadRightTableViewCell.m
//  NeteaseNews
//
//  Created by liutaifeng on 16/4/23.
//  Copyright © 2016年 liutaifeng. All rights reserved.
//

#import "LTFReadRightTableViewCell.h"
#import "UIImageView+AFNetworking.h"
#import "YYImage.h"
#import "IsNight.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@interface LTFReadRightTableViewCell ()
@property (nonatomic, retain) UIImageView *titleImageView;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *subscribeLabel;//订阅数
@property (nonatomic, retain) UIButton *button;
@end

@implementation LTFReadRightTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return  self;
}
- (void)createView {
    
    self.model = [[[LTFReadMarkRightModel alloc] init] autorelease];
    self.titleImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_titleImageView];
    [_titleImageView release];
    
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    self.subscribeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_subscribeLabel];
    [_subscribeLabel release];
    
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    _button.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_button];
}
- (void)layoutSubviews {
    [super layoutSubviews];
    if ([IsNight nowIsNight]) {
        _titleLabel.textColor = [IsNight textNightColor];
        self.contentView.backgroundColor = [UIColor blackColor];
        _subscribeLabel.textColor = [IsNight textNightColor];
    }
    else {
        _titleLabel.textColor = [UIColor blackColor];
        self.contentView.backgroundColor = [UIColor whiteColor];
        _subscribeLabel.textColor = [UIColor blackColor];
    }
    self.titleImageView.frame = CGRectMake(20, 10, WIDTH / 4 + 20, HEIGHT - 20);
    
    
    
    
    NSURL *url = [NSURL URLWithString:self.model.pic];
    NSData *data = [NSData dataWithContentsOfURL:url];
    self.titleImageView.image = [YYImage imageWithData:data];
    
    
    
    
    self.titleLabel.frame = CGRectMake(WIDTH / 4 + 60, 10, WIDTH / 3, 30);
    self.titleLabel.text = self.model.title;
    self.subscribeLabel.frame = CGRectMake(WIDTH / 4 + 60, HEIGHT - 40, WIDTH / 3, 30);
    self.subscribeLabel.text = self.model.subscribe;
    self.subscribeLabel.textColor = [UIColor grayColor];
    self.subscribeLabel.font = [UIFont systemFontOfSize:13];
    self.button.frame = CGRectMake(WIDTH / 5 * 4, 10, HEIGHT - 30, HEIGHT  - 30);
    self.button.center = CGPointMake(WIDTH / 5 * 4 + 20, self.contentView.center.y);
    [self.button setTitle:@"+" forState:UIControlStateNormal];
    self.button.titleLabel.font = [UIFont systemFontOfSize:17];
    self.button.tintColor = [UIColor whiteColor];
    self.button.layer.cornerRadius = (HEIGHT - 30) / 2;
}
@end
